package com.xuan.webfinally.controller;


import com.xuan.webfinally.entity.BoWa;
import com.xuan.webfinally.entity.DeviceStatus;
import com.xuan.webfinally.entity.LabelValueDTO;
import com.xuan.webfinally.entity.MonitoringRequest;
import com.xuan.webfinally.entity.OnTimeData;
import com.xuan.webfinally.entity.Pax;
import com.xuan.webfinally.entity.leida;
import com.xuan.webfinally.entity.pax1;
import com.xuan.webfinally.entity.SensorDataDTO;
import com.xuan.webfinally.entity.jiancegaikuang;
import com.xuan.webfinally.entity.pax2;
import com.xuan.webfinally.entity.pax4;
import com.xuan.webfinally.entity.pax5;
import com.xuan.webfinally.entity.pax6;
import com.xuan.webfinally.entity.wurenji;
import com.xuan.webfinally.service.ISlopeCrackDataService;
import com.xuan.webfinally.service.ISlopeDeviceInfoService;
import com.xuan.webfinally.service.ISlopeInfoService;
import com.xuan.webfinally.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/bpsjjc")
public class bpsjjcController {


    @Autowired
    private ISlopeInfoService  slopeInfoService;


    @Autowired
    private ISlopeCrackDataService slopeCrackDataService;


    @Autowired
    private ISlopeDeviceInfoService slopeDeviceInfoService;

    // 1 .获取监测概况：
    @GetMapping("/monitoring-overview")
    public Result<jiancegaikuang> getMonitoringOverview(HttpServletRequest request)
    {
        // 1. 获取当前登录用户
        String username = request.getHeader("X-Username");
        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
        System.out.println("当前登录部门：" + deptId );
        System.out.println("当前登录用户：" + username);
        //todo 2. 根据当前用户获取所拥有的边坡范围

        //3.获取信息
        jiancegaikuang jiancegaikuang = slopeInfoService.getMonitoringOverviews(username,deptId);

        return Result.success(jiancegaikuang);
    }


    // 根据部门ID来查询
    @GetMapping("device-status")
    public Result<DeviceStatus> getDeviceStatus(HttpServletRequest request)
    {
        // 1. 获取当前登录用户
        String username = request.getHeader("X-Username");
        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//        System.out.println("当前登录用户：" + username);
        //todo 2. 根据当前用户获取所拥有的相关设备权限
        //3.获取信息
        DeviceStatus deviceStatus = slopeInfoService.getDeviceStatus(username,deptId);

        System.out.println(deviceStatus + "这里有问题");
//         = slopeInfoService.getDeviceStatus();

        return Result.success(deviceStatus);
    }
    @GetMapping("warning-info")
    public Result<Map<String, Object>> getWarningInfo(HttpServletRequest request)
    {
        // 1. 获取当前登录用户
        String username = request.getHeader("X-Username");
        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
        System.out.println("当前登录用户：" + username);
        //todo 2. 根据当前用户获取所拥有的边坡范围

        Map<String, Object> warningInfo = slopeInfoService.getWarningInfo(username,deptId);

        System.out.println(warningInfo + "看一下这里");
        //3.获取信息
//        bpjcWarning warningInfo = slopeInfoService.getWarningInfo(username);


        return Result.success(warningInfo);
    }

    @GetMapping("all-points-data")
    public Result<List<List<LabelValueDTO>>> getLineData(HttpServletRequest request) {
        String username = request.getHeader("X-Username");
        Long deptIds = Long.valueOf(request.getHeader("X-DeptId"));
        System.out.println("当前登录用户：" + username);
        Long deptId = slopeDeviceInfoService.getDeptIdByUserName(username);

        // 先定义变量
        List<LabelValueDTO> lineData = null;
        List<LabelValueDTO> lineData2 = null;
        List<LabelValueDTO> lineData3 = null;
        List<LabelValueDTO> lineData4 = null;
        List<LabelValueDTO> lineData5 = null;

        // 正确地赋值，不要重新声明
        if (deptId == 101L) {
            lineData = slopeCrackDataService.getLineDataOne(101L);
        } else if (deptId == 102L) {
            lineData2 = slopeCrackDataService.getLineDataOne(102L);
        } else if (deptId == 103L) {
            lineData3 = slopeCrackDataService.getLineDataOne(103L);
        } else if (deptId == 104L){
            lineData4 = slopeCrackDataService.getLineDataOne(104L);
            lineData5 = slopeCrackDataService.getLineDataOne(104L);
        }

        // 最终统一封装
        List<List<LabelValueDTO>> lineDataList = new ArrayList<>();
        lineDataList.add(lineData);
        lineDataList.add(lineData2);
        lineDataList.add(lineData3);
        lineDataList.add(lineData4);
        lineDataList.add(lineData5);
        System.out.println(lineData4);
        System.out.println(lineData5);
        return Result.success(lineDataList);
    }

    @GetMapping("/equipment-statistics")
    public Result<Map<String, Object>> getMonitoringData(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "4") int size,
            @RequestParam(required = false) String jcClass,
            @RequestParam(required = false) String yjStatus,
            @RequestParam(required = false) String cdStatus
    ) {
        MonitoringRequest request = new MonitoringRequest(page, size, jcClass, yjStatus, cdStatus);
        return Result.success(slopeCrackDataService.getStatistics(request));
    }


    @GetMapping("/device-statisticsnew")
    public Result<List<SensorDataDTO>> getDeviceStatisticsNew() {
//        MonitoringRequest request = new MonitoringRequest(page, size, jcClass, yjStatus, cdStatus);
        return Result.success(slopeCrackDataService.getDeviceStatisticsNew());
    }

    @GetMapping("/onTime_Data")
    public Result<List<OnTimeData>> getOnTimeData() {
//        String username = request.getHeader("X-Username");
//        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//        System.out.println("当前登录用户：" + username);
        List<OnTimeData> onTimeData = slopeInfoService.getOnTimeData();
        return Result.success(onTimeData);
    }

    @GetMapping("/getERZhe")
    public Result<Map<String, Integer>> getERZhe() {
        String normal = "异常项目";
        int NormalCount = slopeInfoService.getNormalCount();
        String warning = "正常项目";
        int WarningCount = 5 - NormalCount;


        return Result.success(Map.of(normal, NormalCount, warning, WarningCount));
    }


    // 裂缝
    @GetMapping("/Pax")
    public Result<List<Map<String,Object>>> getPax(HttpServletRequest request) {
        try {
            // 从请求头获取边坡编号
            String monitorId = request.getHeader("X_monoitor");
//            Map<String, Object> resultList = new HashMap<>();
            System.out.println("hhhjljnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" + monitorId);

            // 调用服务层获取数据
            List<Pax> pax = slopeInfoService.getPaxs(monitorId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
            // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
            for (int i = 0; i < pax.size(); i++) {
                    Map<String, Object> map = new HashMap<>();
                    Pax pax1 = pax.get(i);
//                    map.put("设备SN", pax1.getDeviceSn());
                    map.put("裂缝累计变化量（单位毫米）", pax1.getCrackChange());
//                    map.put("x轴方向倾斜角度", pax1.getXTiltAngle());
//                    map.put("y轴方向倾斜角度", pax1.getYTiltAngle());
//                    map.put("z轴方向倾斜角度", pax1.getZTiltAngle());
//                    map.put("xy倾斜角度", pax1.getXyTiltAngle());
//                    map.put("方位角", pax1.getAzimuth());
//                    map.put("x轴方向加速度及瞬间冲击加速度", pax1.getXAcceleration());
//                    map.put("y轴方向加速度及瞬间冲击加速度", pax1.getYAcceleration());
//                    map.put("z轴方向加速度及瞬间冲击加速度", pax1.getZAcceleration());
                    map.put("采集时间", pax1.getCreateTime());
                    String sensorCode = slopeInfoService.getSensorCode(pax1.getMonitorId(),pax1.getDeviceSn());
                    map.put("传感器编码", sensorCode); // 获取的是传感器编码
//                    map.put("更新时间", pax.getUpdateTime());
                    resultList.add(map);
                }

                }else {
                Map<String, Object> map = new HashMap<>();
                    map.put("无数据", "无数据");
                    resultList.add(map);
                }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }


    // 倾角数据
    @GetMapping("/Pax2")
    public Result<List<Map<String,Object>>> getPax1(HttpServletRequest request) {
//        String monitorId = request.getHeader("X_monoitor");
//        try {
//            // 从请求头获取部门ID
//            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
////          Map<String, Object> resultList = new HashMap<>();
//            Map<String, Object> map = new HashMap<>();
//            // 调用服务层获取数据
//            pax1 pax = slopeInfoService.getPax1(deptId);
//
//            if (pax == null){
//                map.put("无数据", "无数据");
//            }else {
//                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
//
//                map.put("设备SN", pax.getDeviceSn());
////                map.put("裂缝累计变化量（单位毫米）", pax.getCr
//                map.put("x轴方向倾斜角度", pax.getXTiltAngle());
//                map.put("y轴方向倾斜角度", pax.getYTiltAngle());
//                map.put("z轴方向倾斜角度", pax.getZTiltAngle());
//                map.put("xy倾斜角度", pax.getXyTiltAngle());
//                map.put("方位角", pax.getAzimuth());
//                map.put("x轴方向加速度及瞬间冲击加速度", pax.getXAcceleration());
//                map.put("y轴方向加速度及瞬间冲击加速度", pax.getYAcceleration());
//                map.put("z轴方向加速度及瞬间冲击加速度", pax.getZAcceleration());
//                map.put("采集时间", pax.getCreateTime());
//                map.put("更新时间", pax.getUpdateTime());
//
//            }
//
//            // 返回成功结果
//            return Result.success(map);
//        } catch (NumberFormatException e) {
//            // 处理部门ID转换异常
//            return Result.error("部门ID格式错误");
//        } catch (Exception e) {
//            // 处理其他异常
//            return Result.error("获取数据失败：" + e.getMessage());
//        }
        try {
            // 从请求头获取部门ID
            String monitorId = request.getHeader("X_monoitor");
//            Map<String, Object> resultList = new HashMap<>();

            // 调用服务层获取数据
            List<pax1> pax = slopeInfoService.getPax1(monitorId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
                for (int i = 0; i < pax.size(); i++) {
                    pax1 pax1 = pax.get(i);
                    Map<String, Object> map = new HashMap<>();
                    map.put("设备SN", pax1.getDeviceSn());
//                map.put("裂缝累计变化量（单位毫米）", pax1.get;
                map.put("x轴方向倾斜角度", pax1.getXTiltAngle());
                map.put("y轴方向倾斜角度", pax1.getYTiltAngle());
                map.put("z轴方向倾斜角度", pax1.getZTiltAngle());
                map.put("xy倾斜角度", pax1.getXyTiltAngle());
                map.put("方位角", pax1.getAzimuth());
//                map.put("x轴方向加速度及瞬间冲击加速度", pax1.getXAcceleration());
//                map.put("y轴方向加速度及瞬间冲击加速度", pax1.getYAcceleration());
//                map.put("z轴方向加速度及瞬间冲击加速度", pax1.getZAcceleration());
                map.put("采集时间", pax1.getCreateTime());
//                map.put("更新时间", pax1.getUpdateTime());
                String sensorCode = slopeInfoService.getSensorCode(pax1.getMonitorId(),pax1.getDeviceSn());
                map.put("传感器编码", sensorCode); // 获取的是传感器编
                         resultList.add(map);
                    }
                }
            else {
                Map<String, Object> map = new HashMap<>();
                map.put("无数据", "无数据");
                resultList.add(map);
            }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    // 护栏网
    @GetMapping("/Pax3")
    public Result<List<Map<String,Object>>> getPax2(HttpServletRequest request) {
//        try {
//            // 从请求头获取部门ID
//            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//
//            // 调用服务层获取数据
//            pax2 paxData = slopeInfoService.getPax2(deptId);
//
//            // 转换为Map（使用注释中的中文名称作为key）
//            Map<String, Object> map = new HashMap<>();
//
//            if (paxData != null) {
//                map.put("设备SN", paxData.getDeviceSn());
//                map.put("x轴方向倾斜角度(°)", paxData.getXTiltAngle());
//                map.put("y轴方向倾斜角度(°)", paxData.getYTiltAngle());
//                map.put("z轴方向倾斜角度(°)", paxData.getZTiltAngle());
//                map.put("x轴方向加速度及瞬间冲击加速度(mg)", paxData.getXAcceleration());
//                map.put("y轴方向加速度及瞬间冲击加速度(mg)", paxData.getYAcceleration());
//                map.put("z轴方向加速度及瞬间冲击加速度(mg)", paxData.getZAcceleration());
//                map.put("采集时间", paxData.getCreateTime());
//                map.put("更新时间", paxData.getUpdateTime());
//                map.put("x轴倾斜角累计变化量", paxData.getXTiltAngleChange());
//                map.put("y轴倾斜角累计变化量", paxData.getYTiltAngleChange());
//                map.put("z轴倾斜角累计变化量", paxData.getZTiltAngleChange());
//                map.put("xy轴倾斜角累计变化量", paxData.getXyTiltAngleChange());
//            }else {
//                map.put("无数据", "无数据");
//            }
//
//            // 返回成功结果
//            return Result.success(map);
//        } catch (NumberFormatException e) {
//            // 处理部门ID转换异常
//            return Result.error("部门ID格式错误");
//        } catch (Exception e) {
//            // 处理其他异常
//            return Result.error("获取数据失败：" + e.getMessage());
//        }
        try {
            // 从请求头获取部门ID
            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//            Map<String, Object> resultList = new HashMap<>();

            // 调用服务层获取数据
            List<List<pax2>> pax = slopeInfoService.getPax2(deptId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
                for (int i = 0; i < pax.size(); i++) {
                    List<pax2> paxList = pax.get(i);
                    for (int j = 0; j < paxList.size(); j++) {
                        Map<String, Object> map = new HashMap<>();
                        pax2 paxData = paxList.get(j);

                        map.put("设备SN", paxData.getDeviceSn());
                map.put("x轴方向倾斜角度(°)", paxData.getXTiltAngle());
                map.put("y轴方向倾斜角度(°)", paxData.getYTiltAngle());
                map.put("z轴方向倾斜角度(°)", paxData.getZTiltAngle());
                map.put("x轴方向加速度及瞬间冲击加速度(mg)", paxData.getXAcceleration());
                map.put("y轴方向加速度及瞬间冲击加速度(mg)", paxData.getYAcceleration());
                map.put("z轴方向加速度及瞬间冲击加速度(mg)", paxData.getZAcceleration());
                map.put("采集时间", paxData.getCreateTime());
                map.put("更新时间", paxData.getUpdateTime());
                map.put("x轴倾斜角累计变化量", paxData.getXTiltAngleChange());
                map.put("y轴倾斜角累计变化量", paxData.getYTiltAngleChange());
                map.put("z轴倾斜角累计变化量", paxData.getZTiltAngleChange());
                map.put("xy轴倾斜角累计变化量", paxData.getXyTiltAngleChange());
                        String sensorCode = slopeInfoService.getSensorCode(paxData.getMonitorId(),paxData.getDeviceSn());
                        map.put("传感器编码", sensorCode); // 获取的是传感器编
                        resultList.add(map);
                    }
                }
            }else {
                Map<String, Object> map = new HashMap<>();
                map.put("无数据", "无数据");
                resultList.add(map);
            }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    // slope_geoacoustic_data 地声
    @GetMapping("/pax4")
    public Result<List<Map<String,Object>>> getPax3(HttpServletRequest request) {
//        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//        pax4 paxData = slopeInfoService.getPax4(deptId);
//        Map<String, Object> map = new HashMap<>();
//        if (paxData != null) {
//            map.put("设备SN", paxData.getDeviceSn());
//            map.put("原始声压", paxData.getOriginalSoundPressure());
//            map.put("有效声压", paxData.getEffectiveSoundPressure());
//            map.put("频率", paxData.getFrequencySignal());
//            map.put("采集时间", paxData.getCreateTime());
//            map.put("更新时间", paxData.getUpdateTime());
//        }else {
//            map.put("无数据", "无数据");
//        }
//
//        return Result.success(map);
        try {
            // 从请求头获取部门ID
            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//            Map<String, Object> resultList = new HashMap<>();

            // 调用服务层获取数据
            List<List<pax4>> pax = slopeInfoService.getPax4(deptId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
                for (int i = 0; i < pax.size(); i++) {
                    List<pax4> paxList = pax.get(i);
                    for (int j = 0; j < paxList.size(); j++) {
                        Map<String, Object> map = new HashMap<>();
                        pax4 paxData = paxList.get(j);

                        map.put("设备SN", paxData.getDeviceSn());
                        map.put("原始声压", paxData.getOriginalSoundPressure());
                        map.put("有效声压", paxData.getEffectiveSoundPressure());
                        map.put("频率", paxData.getFrequencySignal());
                        map.put("采集时间", paxData.getCreateTime());
                        map.put("更新时间", paxData.getUpdateTime());
                        String sensorCode = slopeInfoService.getSensorCode(paxData.getMonitorId(),paxData.getDeviceSn());
                        map.put("传感器编码", sensorCode); // 获取的是传感器编
                        resultList.add(map);
                    }
                }
            }else {
                Map<String, Object> map = new HashMap<>();
                map.put("无数据", "无数据");
                resultList.add(map);
            }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }

    }

    @GetMapping("/pax5")
    public Result<List<Map<String,Object>>> getPax4(HttpServletRequest request) {
//        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//        System.out.println("00000000000000000000000000000000000000000000000000011111111122222222222488888" + deptId);
//        pax5 paxData = slopeInfoService.getPax5(deptId);
//        Map<String, Object> map = new HashMap<>();
//        if (paxData != null) {
//            map.put("设备SN", paxData.getDeviceSn());
//            map.put("地面以下所监测层位土壤中的温度(°C)", paxData.getSoilTemperature0());
//            map.put("土壤中水分占有体积和土壤总体积比值(%)", paxData.getSoilMoistureRatio0());
//            map.put("采集时间", paxData.getCreateTime());
//            map.put("更新时间", paxData.getUpdateTime());
//            map.put("soilTemperature2", paxData.getSoilTemperature2());
//            map.put("soilTemperature3", paxData.getSoilTemperature3());
//            map.put("soilTemperature4", paxData.getSoilTemperature4());
//            map.put("soilTemperature1", paxData.getSoilTemperature1());
//            map.put("soilMoistureRatio1", paxData.getSoilMoistureRatio1());
//            map.put("soilMoistureRatio2", paxData.getSoilMoistureRatio2());
//            map.put("soilMoistureRatio3", paxData.getSoilMoistureRatio3());
//            map.put("soilMoistureRatio4", paxData.getSoilMoistureRatio4());
//
//        }else {
//            map.put("无数据", "无数据");
//        }
//        return Result.success(map);

        try {
            // 从请求头获取部门ID
            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//            Map<String, Object> resultList = new HashMap<>();

            // 调用服务层获取数据
            List<List<pax5>> pax = slopeInfoService.getPax5(deptId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
                for (int i = 0; i < pax.size(); i++) {
                    List<pax5> paxList = pax.get(i);
                    for (int j = 0; j < paxList.size(); j++) {
                        Map<String, Object> map = new HashMap<>();
                        pax5 paxData = paxList.get(j);

                        map.put("设备SN", paxData.getDeviceSn());
            map.put("地面以下所监测层位土壤中的温度(°C)", paxData.getSoilTemperature0());
            map.put("土壤中水分占有体积和土壤总体积比值(%)", paxData.getSoilMoistureRatio0());
            map.put("采集时间", paxData.getCreateTime());
            map.put("更新时间", paxData.getUpdateTime());
            map.put("2层土壤温度", paxData.getSoilTemperature2());
            map.put("3层土壤温度", paxData.getSoilTemperature3());
            map.put("4层土壤温度", paxData.getSoilTemperature4());
            map.put("1层土壤温度", paxData.getSoilTemperature1());
            map.put("1层土壤湿度", paxData.getSoilMoistureRatio1());
            map.put("2层土壤湿度", paxData.getSoilMoistureRatio2());
            map.put("3层土壤湿度", paxData.getSoilMoistureRatio3());
            map.put("4层土壤湿度", paxData.getSoilMoistureRatio4());
                        String sensorCode = slopeInfoService.getSensorCode(paxData.getMonitorId(),paxData.getDeviceSn());
                        map.put("传感器编码", sensorCode); // 获取的是传感器编
                        resultList.add(map);
                    }
                }
            }else {
                Map<String, Object> map = new HashMap<>();
                map.put("无数据", "无数据");
                resultList.add(map);
            }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

    @GetMapping("/pax6")
    public Result<List<Map<String,Object>>> getPax5(HttpServletRequest request) {
//        Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//        pax6 paxData = slopeInfoService.getPax6(deptId);
//        Map<String, Object> map = new HashMap<>();
//        if (paxData != null) {
//            map.put("设备SN", paxData.getDeviceSn());
//            map.put("累计雨量(mm)", paxData.getCumulativeRainfall());
//            map.put("日雨量(mm)", paxData.getDailyRainfall());
//            map.put("小时雨量(mm)", paxData.getHourlyRainfall());
//            map.put("最小雨量(mm)", paxData.getMinRainfall());
//            map.put("温度(°C)", paxData.getTemperature());
//            map.put("压力(kPa)", paxData.getPressure());
//            map.put("风速(m/s)", paxData.getWindSpeed());
//            map.put("风向(°)", paxData.getWindDirection());
//            map.put("湿度(%)", paxData.getHumidity());
//            map.put("太阳辐射(W/m^2)", paxData.getSolarRadiation());
//            map.put("采集时间", paxData.getCreateTime());
//            map.put("更新时间", paxData.getUpdateTime());
//        }else {
//            map.put("无数据", "无数据");
//        }
//        return Result.success(map);

        try {
            // 从请求头获取部门ID
            Long deptId = Long.valueOf(request.getHeader("X-DeptId"));
//            Map<String, Object> resultList = new HashMap<>();

            // 调用服务层获取数据
            List<List<pax6>> pax = slopeInfoService.getPax6(deptId);
            List<Map<String,Object>> resultList = new ArrayList<>();

            if (pax != null){
                // 遍历Pax对象列表，转换为Map（使用注释中的中文名称作为key）
                for (int i = 0; i < pax.size(); i++) {
                    List<pax6> paxList = pax.get(i);
                    for (int j = 0; j < paxList.size(); j++) {
                        Map<String, Object> map = new HashMap<>();
                        pax6 paxData = paxList.get(j);

                        map.put("设备SN", paxData.getDeviceSn());
                        map.put("累计雨量(mm)", paxData.getCumulativeRainfall());
                        map.put("日雨量(mm)", paxData.getDailyRainfall());
                        map.put("小时雨量(mm)", paxData.getHourlyRainfall());
                        map.put("最小雨量(mm)", paxData.getMinRainfall());
                        map.put("温度(°C)", paxData.getTemperature());
                        map.put("压力(kPa)", paxData.getPressure());
                        map.put("风速(m/s)", paxData.getWindSpeed());
                        map.put("风向(°)", paxData.getWindDirection());
                        map.put("湿度(%)", paxData.getHumidity());
                        map.put("太阳辐射(W/m^2)", paxData.getSolarRadiation());
                        map.put("采集时间", paxData.getCreateTime());
                        map.put("更新时间", paxData.getUpdateTime());
                        String sensorCode = slopeInfoService.getSensorCode(paxData.getMonitorId(),paxData.getDeviceSn());
                        map.put("传感器编码", sensorCode); // 获取的是传感器编
                        resultList.add(map);
                    }
                }
            }else {
                Map<String, Object> map = new HashMap<>();
                map.put("无数据", "无数据");
                resultList.add(map);
            }



            // 返回成功结果
            return Result.success(resultList);
        } catch (NumberFormatException e) {
            // 处理部门ID转换异常
            return Result.error("部门ID格式错误");
        } catch (Exception e) {
            // 处理其他异常
            return Result.error("获取数据失败：" + e.getMessage());
        }
    }

//    @GetMapping("/getBoWa")
//    public Result<> getBoWa() {
//    }
    @GetMapping("/leida")
    public Result<List<leida>> getLWa(){
        List<leida>BoWaList = slopeInfoService.getLeida();
        for (int i = 0; i < BoWaList.size(); i++) {
            BoWaList.get(i).setImgPath("http://39.107.238.187/prod-api"+ BoWaList.get(i).getImgPath());
        }
        return Result.success(BoWaList);
    }


    @GetMapping("/Bowa")
    public Result<List<BoWa>> getBowa() {
        List<BoWa> BoWaList = slopeInfoService.getBowa();
        for (int i = 0; i < BoWaList.size(); i++) {
            BoWaList.get(i).setPicPath("http://39.107.238.187/prod-api"+ BoWaList.get(i).getPicPath());
        }
        return Result.success(BoWaList);
    }

    @GetMapping("/WuRenJi")
    public Result<List<wurenji>> getWuRenJi() {
        List<wurenji> WuRenJiList = slopeInfoService.getWuRenJi();
        for (int i = 0; i < WuRenJiList.size(); i++) {
            WuRenJiList.get(i).setImg("http://39.107.238.187/prod-api"+ WuRenJiList.get(i).getImg());
        }

        return Result.success(WuRenJiList);
    }

}
